home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / recover / recoverUndoTrans.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  5.5 KB  |  217 lines

  1. /*
  2.  *   $RCSfile: recoverUndoTrans.c,v $  
  3.  *   $Revision: 1.2 $  
  4.  *   $Date: 1996/05/04 23:51:54 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38. #include "sysdefs.h"
  39. #include "ess.h"
  40. #include "checking.h"
  41. #include "trace.h"
  42. #include "error.h"
  43. #include "list.h"
  44. #include "pool.h"
  45. #include "tid.h"
  46. #include "io.h"
  47. #include "lock.h"
  48. #include "object.h"
  49. #include "msgdefs.h"
  50. #include "thread.h"
  51. #include "semaphore.h"
  52. #include "latch.h"
  53. #include "link.h"
  54. #include "lsn.h"
  55. #include "bf.h"
  56. #include "log.h"
  57. #include "volume.h"
  58. #include "openlog.h"
  59. #include "trans.h"
  60. #include "logrecs.h"
  61. #include "log_intfuncs.h"
  62. #include "log_extfuncs.h"
  63. #include "lm_extfuncs.h"
  64. #include "trans_intfuncs.h"
  65. #include "trans_extfuncs.h"
  66. #include "recover_intfuncs.h"
  67. #include "thread_funcs.h"
  68. #include "thread_globals.h"
  69. #include "trans_globals.h"
  70. #include "recover_globals.h"
  71.  
  72. #ifdef vax
  73.  void
  74. recoverUndoTrans (
  75.     register TRANSREC   *transRec,
  76. )
  77.  
  78. #else
  79.     /* for all architectures but the vax */
  80.  void
  81. recoverUndoTrans ()
  82. #endif
  83.  
  84. {
  85.     LIST            pendingBitmapList;
  86.  
  87.     /*
  88.      *  This variable holds an argument passed the this function
  89.      *  when the thread was forked.  This should be portable across
  90.      *  all architectures but vax's.
  91.      */
  92. #if defined(vax)
  93.     /* not needed */
  94. #else
  95.     register TRANSREC   *transRec;
  96. #endif
  97.  
  98.     TRACE(TR_TRANS, TR_LEVEL_1);
  99.  
  100.     /*
  101.      *  suck the transrec out of the tcb buffer
  102.      */
  103. #ifdef mips
  104.     SM_ASSERT(LEVEL_1, sizeof(transRec) == sizeof(Active->currentBuf[JB_A0]));
  105.     transRec = (TRANSREC *) Active->currentBuf[JB_A0];
  106. #elif defined(sparc) || defined (_AIX) || defined(hpux) || defined(linux)
  107.     /*
  108.      *  Sparc and other architectures
  109.      */
  110.     SM_ASSERT(LEVEL_1, sizeof(transRec) == sizeof(Active->args[0]));
  111.     transRec = (TRANSREC *) Active->args[0];
  112. #elif defined(vax)
  113.     /* not needed */
  114. #elif !(defined(mips) || defined(sparc) || defined(vax) || defined(_AIX) || defined(hpux) || defined(linux))
  115.     not supported
  116. #else
  117.     /* this else should have the not supported code, but the
  118.        ultrix cpp is broken */
  119. #endif
  120.  
  121.     TRPRINT(TR_LOG|TR_RECOVER, TR_LEVEL_1, ("tid:%d", GETTID(transRec)));
  122.  
  123.     initializeList(&(pendingBitmapList));
  124.  
  125.     /*
  126.      *    Remember the transaction the thread is undoing
  127.      */
  128.     Active->transRec = (char *) transRec;
  129.  
  130.     /*
  131.      *  Free all information on files and pages
  132.      *  deallocated by this transaction
  133.      */
  134.     freeFileDeallocInfo(transRec);
  135.     freePageDeallocInfo(transRec);
  136.  
  137.     undoTransaction(NULL_LSN, transRec->nextUndoLSN, LOG_RECOVERY);
  138.  
  139.     /*
  140.      *    check to see if there are any log records
  141.      *    that are written for this transaction
  142.      */
  143.     if (transRec->logRecordCount > 0)    {
  144.  
  145.         /*
  146.          *  add all the pages in the all the files to be destroyed
  147.          *  to the list of pages to deallocate
  148.          */
  149.         if (transDeallocFilePages(transRec) != esmNOERROR) {
  150.             /* clean up dealloc info */
  151.             SM_ERROR(TYPE_CRASH, esmINTERNAL);
  152.         }
  153.  
  154.         /*
  155.          *  Log all pending page deallocations
  156.          */
  157.         if (logTransDeallocPages(transRec, &pendingBitmapList) != esmNOERROR) {
  158.             /*
  159.              *  For now, just crash, but we should really clean things up
  160.              *  and abort the transaction.  Clean-up is complicated by
  161.              *  the bitmap and volume header pages which are pinned with
  162.              *  pending operations.
  163.              */
  164.             SM_ERROR(TYPE_CRASH, esmINTERNAL);
  165.         }
  166.  
  167.         /*
  168.          *    we must log the final abort record, it need not be
  169.          *    forced to disk
  170.          */
  171.         if (writeTransStateRecord(transRec, LOG_REC_TYPE_ABORT, ZERO, T_ABORT, FALSE) < esmNOERROR)    {
  172.  
  173.             SM_ERROR(TYPE_FATAL, Active->errno);
  174.         }
  175.  
  176.         /*
  177.          *  Perform all pending page deallocations
  178.          */
  179.         if (deallocTransPages(transRec, &pendingBitmapList) != esmNOERROR) {
  180.             SM_ERROR(TYPE_FATAL, esmINTERNAL);
  181.         }
  182.  
  183.         /*
  184.          *    take the record off the log queue
  185.          */
  186.         removeLogList(transRec);
  187.     }
  188.  
  189.     /*
  190.      *    Thread is no longer undoing a transaction
  191.      */
  192.     Active->transRec = NULL;
  193.  
  194.     /*
  195.      *    free all the locks
  196.      */
  197.     unlockAll(transRec, esmTRANSABORTED);
  198.  
  199.     /*
  200.      *    free the structures
  201.      */
  202.     freeTransVolRecs(transRec);
  203.  
  204.     /*
  205.      *    give back the transaction record
  206.      */
  207.     freeTransRec(transRec);
  208.  
  209.     /* thread is now done, so cleanup and wakeup any waiter */
  210.     SM_ASSERT(LEVEL_3, UndoForkCount > 0);
  211.     UndoForkCount--;
  212.     notify(&RecoverUndoWaitList, esmNOERROR, esmNOERROR);
  213.     threadRestart();    
  214.  
  215.     return;
  216. }
  217.